﻿SET QUOTED_IDENTIFIER ON
SET ARITHABORT ON
SET NUMERIC_ROUNDABORT OFF
SET CONCAT_NULL_YIELDS_NULL ON
SET ANSI_NULLS ON
SET ANSI_PADDING ON
SET ANSI_WARNINGS ON

GO


CREATE PROCEDURE [dbo].[bhp_NemoBlogPosts_GetByTag](
	@TagId			INT,
	@OnlyPublic	BIT = 0,
	@Language		NCHAR(5) = 'pl-PL'
)
AS
BEGIN

	SELECT 
		* 
	FROM 
		BLOG_POSTS p
		INNER JOIN BLOG_POSTS_tags pt ON p.idx = pt.idx
	WHERE
		pt.rel = @TagId
		AND (@OnlyPublic = 0 OR published = 1)
		AND p.del = 0
		AND pt.del = 0
	ORDER BY ISNULL(publishDate,  dbo.n_DateTimeToDT(p.ctime)) DESC
		

END
GO
